/' Copyright (c) 2007 Scott Lembcke
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 '/

#ifndef CHIPMUNK_HEADER
#define CHIPMUNK_HEADER	1

'' * FreeBASIC Note: I've permanently allowed private access to avoid preprocessor name mangling
'' This means some of these headers have been modified during the translation, but the behaviour
'' is the same.

declare sub cpMessage cdecl alias "cpMessage" ( byval as zstring ptr, byval as zstring ptr, byval as zstring ptr, byval as integer, byval as integer )
#ifdef NDEBUG
	#define	cpAssertWarn(condition, message)
#else
	#define cpAssertWarn(condition, message) if (not (condition)) then cpMessage(message, #condition, __FILE__, __LINE__, 0)
#endif

'' Hard assertions are important and cheap to execute. They are not disabled by compiling as debug.
#define cpAssertHard(condition, message) if not (condition) then cpMessage(message, #condition, __FILE__, __LINE__, 1)

#ifdef NDEBUG
	#define	cpAssert(condition, message)
#else
	#define cpAssert(condition, message) if (not(condition)) then cpMessage(message, #condition, __FILE__, __LINE__, 1)
#endif

#include "chipmunk_types.bi"

'' Maximum allocated size for various Chipmunk buffer sizes
#define CP_BUFFER_BYTES (32*1024)

#include "crt/stdlib.bi"	'' Get malloc() and friends..
#define cpmalloc malloc
#define cpcalloc calloc
#define cprealloc realloc
#define cpfree free

'' * FreeBASIC Note: I added this for the sake of sanity
#ifndef NULL
#define NULL cptr( any ptr, 0 )
#endif

type cpArray_ as cpArray
type cpHashSet_ as cpHashSet

type cpBody_ as cpBody
type cpShape_ as cpShape
type cpConstraint_ as cpConstraint

type cpCollisionHandler_ as cpCollisionHandler
type cpArbiter_ as cpArbiter

type cpSpace_ as cpSpace

#include once "cpVect.bi"
#include once "cpBB.bi"
#include once "cpSpatialIndex.bi"

#include once "cpBody.bi"
#include once "cpShape.bi"
#include once "cpPolyShape.bi"

#include once "cpArbiter.bi"
#include once "constraints/cpConstraint.bi"

#include once "cpSpace.bi"

#define CP_VERSION_MAJOR 6
#define CP_VERSION_MINOR 0
#define CP_VERSION_RELEASE 0

extern cpVersionString alias "cpVersionString" as const zstring ptr
declare sub cpInitChipmunk cdecl alias "cpInitChipmunk" ()

'' [NOTE] I added this function for ease of use
function cpVersion() as string
	return str( *cpVersionString )
end function

'' Calculate the moment of inertia for a circle, r1 and r2 are the inner and outer diameters.
'' (A solid circle has an inner diameter of 0)
declare function cpMomentForCircle cdecl alias "cpMomentForCircle" ( byval as cpFloat, byval as cpFloat, byval as cpFloat, byval as cpVect ) as cpFloat
'' Calculate area of a hollow circle
declare function cpAreaForCircle cdecl alias "cpAreaForCircle" ( byval as cpFloat, byval as cpFloat ) as cpFloat

'' Calculate the moment of inertia for a line segment. (beveling radius not supported)
declare function cpMomentForSegment cdecl alias "cpMomentForSegment" ( byval as cpFloat, byval as cpVect, byval as cpVect ) as cpFloat
'' Calculate the area of a fattened (capsule shaped) line segment.
declare function cpAreaForSegment cdecl alias "cpAreaForSegment" ( byval as cpVect, byval as cpVect ) as cpFloat

'' Calculate the moment of inertia for a solid polygon shape.
declare function cpMomentForPoly cdecl alias "cpMomentForPoly" ( byval as cpFloat, byval as integer, byval as const cpVect ptr, byval as cpVect ) as cpFloat
'' Calculate the signed area of a polygon
declare function cpAreaForPoly cdecl alias "cpAreaForPoly" ( byval as const integer, byval as const cpVect ptr ) as cpFloat
'' Calculate the natural centroid of a polygon
declare function cpCentroidForPoly cdecl alias "cpCentroidForPoly" ( byval as const integer, byval as const cpVect ptr ) as cpVect
'' Center the polygon on the origin.  (Subtracts the centroid of the polygon from each vertex)
declare sub cpRecenterPoly cdecl alias "cpRecenterPoly" ( byval as const integer, byval as cpVect ptr )

'' Calculate the moment of inertia for a solid box.
declare function cpMomentForBox cdecl alias "cpMomentForBox" ( byval as cpFloat, byval as cpFloat, byval as cpFloat ) as cpFloat

operator *( byval v as const cpVect, byval s as const cpFloat ) as cpVect
	return cpvmult(v, s)
end operator
operator +( byval v1 as const cpVect, byval v2 as const cpVect ) as cpVect
	return cpvadd( v1, v2 )
end operator
operator -( byval v1 as const cpVect, byval v2 as const cpVect ) as cpVect
	return cpvsub( v1, v2 )
end operator
operator =( byval v1 as const cpVect, byval v2 as const cpVect ) as integer
	return cpveql( v1, v2 )
end operator
operator -( byval v as const cpVect ) as cpVect
	return cpvneg(v)
end operator

#endif
